library(FAIRsimulator)
set.seed(32423)

Background

This example will compare two parallel group designs. The first design, the basic design, has 100 subjects per treatment while the alternative design has 200 subjects per treatment arm.

This is a summary of the common features of the two designs:

The basic design

Create the study with the basic design

StudyObjIni <- createStudy(
  nCohorts = 1,
  recruitmentAges = list(c(6,7)*30),
  nSubjects = c(500),
  cohortStartTimes = c(6*30),
  newCohortLink = list(NULL),
  Recruitmentfunction=function(...) {return(5000)},
  samplingDesign = list(seq(0,12,by=2)*30),
  studyStopTime = 18*30+1,
  latestTimeForNewBirthCohorts=6*30,
  treatments =list(c("SoC-1","TRT-1","TRT-2","TRT-3","TRT-4")),
  effSizes = list(c(0.05,0.1,0.15,0.20,0.25)),
  randomizationProbabilities = list(rep(0.20,5))
  )

Run the study

The study is simulated with the AdaptiveStudy function.

StudyObj <- AdaptiveStudy(StudyObjIni)

Visualise the results

The number of subjects over time

plotActiveSubjects(StudyObj)

The simulated HAZ data

The simulated HAZ values can be inspected using the plotHAZ function.

plotHAZ(StudyObj)

The treatment effects

plotHAZTreatmentEff(StudyObj)

The posterior probabilities

The data can be used to update the posterior probability of the treatments to be better than the other treatments.

tmp <- getProbData(StudyObj,strProb = "UnWeightedUpdateProbabilities",cohortAgeNames="6-18 months")
kable(tmp %>% select(TreatmentName,Prob))

TRT-3 is surprisingly the treatment with the highest probability of being the best treatment. However, this is based on a single realisation of the design. Running the study many times will allow us to compute statistics on the performance of the design.

Running the basic scenario multiple times to get statistics

The basic scenario is run 100 times to get statistics on the randomization probability updates.

iter   <- 100
ncores <- 7

myMultStud <- runMultiSim(StudyObjIni,iter=iter,ncores=ncores)

Extract the probabilities of interest.

probDfUnweightedUpdate <- getMultiProbList(myMultStud[[1]],ncores=ncores, strProb="UnWeightedUpdateProbabilities", cohortAgeNames="6-18 months")  

Summarise the end of treatment probabilities for plotting and tabulation.

sumData <- 
  probDfUnweightedUpdate %>% 
  filter(RandStudyTime == max(RandStudyTime)) %>% 
  group_by(TreatmentName,CohortAge) %>% 
  summarise(
    Mean=mean(Prob),
    Low=quantile(Prob,p=0.025),
    High=quantile(Prob,p=0.975)
    )

Plot and tabulate the treatment probability statistics.

ggplot(sumData,aes(TreatmentName,Mean,color=TreatmentName)) +
  geom_point() +
  geom_errorbar(aes(ymin=Low,ymax=High),width=0.2) +
  facet_wrap(~CohortAge,scales = "free_x")
kable(sumData %>% select(TreatmentName,Mean,Low,High) %>% rename(Treatment =TreatmentName,"P0.025"=Low,"P0.975"=High),dig=2)

The alternative design

set.seed(85859)

Create the study with the alternative design

StudyObjIniAlt <- createStudy(
  nCohorts = 1,
  recruitmentAges = list(c(6,7)*30),
  nSubjects = c(1000),
  cohortStartTimes = c(6*30),
  newCohortLink = list(NULL),
  Recruitmentfunction=function(...) {return(5000)},
  samplingDesign = list(seq(0,12,by=2)*30),
  studyStopTime = 18*30+1,
  latestTimeForNewBirthCohorts=6*30,
  treatments =list(c("SoC-1","TRT-1","TRT-2","TRT-3","TRT-4")),
  effSizes = list(c(0.05,0.1,0.15,0.20,0.25)),
  randomizationProbabilities = list(rep(0.20,5))
  )

Run the study

Execute the study.

StudyObjAlt <- AdaptiveStudy(StudyObjIniAlt)

Visualise the results

The number of subjects over time

plotActiveSubjects(StudyObjAlt)

The simulated HAZ data

The simulated HAZ values can be inspected using the plotHAZ function.

plotHAZ(StudyObjAlt)

The treatment effects

plotHAZTreatmentEff(StudyObjAlt)

The posterior probabilities

The data can be used to update the posterior probability of the treatments to be better than the other treatments.

tmp <- getProbData(StudyObjAlt,strProb = "UnWeightedUpdateProbabilities",cohortAgeNames="6-18 months")
kable(tmp %>% select(TreatmentName,Prob))

Running the alternative scenario multiple times to get statistics

The alternative scenario is run 100 times to get statistics on the randomization probability updates.

iter   <- 100
ncores <- 7

myMultStudAlt <- runMultiSim(StudyObjIniAlt,iter=iter,ncores=ncores)

Extract the probabilities of interest.

probDfUnweightedUpdateAlt <- getMultiProbList(myMultStudAlt[[1]],ncores=ncores, strProb="UnWeightedUpdateProbabilities", cohortAgeNames="6-18 months")  

Summarise the end of treatment probabilities for plotting and tabulation.

sumDataAlt <- 
  probDfUnweightedUpdateAlt %>% 
  filter(RandStudyTime == max(RandStudyTime)) %>% 
  group_by(TreatmentName,CohortAge) %>% 
  summarise(
    Mean=mean(Prob),
    Low=quantile(Prob,p=0.025),
    High=quantile(Prob,p=0.975)
    )

Plot and tabulate the treatment probability statistics.

ggplot(sumDataAlt,aes(TreatmentName,Mean,color=TreatmentName)) +
  geom_point() +
  geom_errorbar(aes(ymin=Low,ymax=High),width=0.2) +
  facet_wrap(~CohortAge,scales = "free_x")
kable(sumDataAlt %>% select(TreatmentName,Mean,Low,High) %>% rename(Treatment =TreatmentName,"P0.025"=Low,"P0.975"=High),dig=2)


eniclas/FAIRsimulator documentation built on May 16, 2019, 5:12 a.m.